package com.example.test;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

/**
 * Created by Administrator on 2018/5/15.
 */

public class SecondActivity extends AppCompatActivity implements View.OnClickListener {
    private EditText number;
    private EditText number1;
    private EditText deal;
    private Button button1;
    private Button button2;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        button1 = findViewById(R.id.but);
        button2 = findViewById(R.id.but2);
        button1.setOnClickListener(this);
        button2.setOnClickListener(this);
        number = findViewById(R.id.num1);
        number1 = findViewById(R.id.num2);
        deal = findViewById(R.id.fuhao);
    }

    public void onClick(View view) {

        switch (view.getId()) {
            case R.id.but:
                double numer = Double.parseDouble(number.getText().toString());
                double numer1 = Double.parseDouble(number1.getText().toString());
                String fu = deal.getText().toString();
                double total = 0;
                switch (fu) {
                    case "+":
                        total = numer + numer1;
                        Toast.makeText(this, "最终计算结果为：" + total, Toast.LENGTH_SHORT).show();
                        break;
                    case "-":
                        total = numer - numer1;
                        Toast.makeText(this, "最终计算结果为：" + total, Toast.LENGTH_SHORT).show();
                        break;
                    case "*":
                        total = numer * numer1;
                        Toast.makeText(this, "最终计算结果为：" + total, Toast.LENGTH_SHORT).show();
                        break;
                    case "/":
                        total = numer / numer1;
                        Toast.makeText(this, "最终计算结果为：" + total, Toast.LENGTH_SHORT).show();
                    default:
                        Toast.makeText(this, "输入错误请重新输入！！！", Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.but2:
                Toast.makeText(this, "即将跳转到下一页。。。", Toast.LENGTH_SHORT).show();
                Intent intent =new Intent(this,ThirdActivity.class);
                startActivity(intent);
                break;
        }
    }
}
